<template>
	<view class="my-path-list">
		
		<view class="path-list">
			
			<view
				v-for="(item,index) in list"
				:key="index"
				@tap="toAddPath(index)"
			>
				<view class="path-item" @tap="goPayOrder(item)">
					<view class="item-main">
						<view class="item-name">{{item.name}}</view>
						<view>{{item.tel}}</view>
					</view>
					<view class="item-main">
						<view class="active" v-if="item.isDefault">默认</view>
						<view>{{item.city}}{{item.details}}</view>
					</view>
					
				</view>
			</view>	
		</view>
		
		
		<view class="add-path">
			<view class="add-path-btn" @tap="goAddPath">新增地址</view>
		</view>
	</view>
</template>

<script>
	// import {mapState} from 'vuex'
	export default {
		data() {
			return {
				isSelectedPath:false
			}
		},
		// computed:{
		// 	...mapState({
		// 		list:state=>state.path.list
		// 	})
		// },
		//接收pay的type=selectedPath，页面跳转不同
		onLoad(e) {
			if(e.type==='selectedPath'){
				this.isSelectedPath=true;
				// console.log('我从确定订单过来的');
			}
		},
		methods: {
			//修改
			toAddPath(index){
				let pathObj = JSON.stringify({
					index:index,
					item:this.list[index]
				})
				
				uni.navigateTo({
					url:("/pages/my-config/my-add-path?data="+pathObj+"")
				})
			},
			//新增
			goAddPath(){
				uni.navigateTo({
					url:('/pages/my-config/my-add-path')
				})
			},
			//返回确认订单页面
			goPayOrder(item){
				//如果从结算页面进入，执行以下代码
				if(this.isSelectedPath){
					//自定义事件，页面通讯
					uni.$emit("selectPathItem",item);
					// console.log(item);
					uni.navigateBack({
						delta:1
					})
				}
				
			}
		}
	}
</script>

<style scoped>
	
	.path-list{
		padding-left: 20rpx;
	}
		.path-item{
			padding: 10rpx;
			border-bottom: 2rpx solid #cccccc;
		}
			.item-main{
				display: flex;
				align-items: center;
			}
			.item-name{
				padding-right: 10rpx;
			}
			.active{
				padding-right: 10rpx;
				background-color: #49a2dd;
				padding:0 8rpx;
				color: #ffffff;
				border-radius: 20rpx;
				font-size: 24rpx;
				text-align: center;
			}
			
			
	.add-path{
		padding: 20rpx 0;
		width: 100%;
		display: flex;
		justify-content: center;
	}
		.add-path-btn{
			border: 2rpx solid #49a2dd;
			border-radius: 30rpx;
			padding: 10rpx 60rpx;
			color: #49a2dd;
		}
	
</style>
